package cn.nr19.jian.utils;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.parser.Parser;
import org.jsoup.parser.XmlTreeBuilder;
import org.jsoup.select.Elements;

import java.util.ArrayList;
import java.util.List;



/**
 * kotlin 报错
 * by Jen. 2021.01.
 */
public class JsoupParserUtils {


    public static List<String> xml(String code, String parameter){
        try {
            List<String> _keys = new ArrayList<>();
            if (parameter.isEmpty()){
                _keys.add(code);
                return _keys;
            }

            // new Parser(new XmlTreeBuilder() kotlin 报错
            Element _e = Jsoup.parse(code, "", new Parser(new XmlTreeBuilder()));
            Elements _es = _e.select(parameter);
            for (Element e : _es) {
                _keys.add(e.outerHtml());
            }

            return _keys;
        }catch (Exception ex){
            ex.printStackTrace();
        }

        return null;

    }
    // new Parser(new XmlTreeBuilder() kotlin 报错
    public static Element getXmlObj(String code){
        return Jsoup.parse(code, "", new Parser(new XmlTreeBuilder()));
    }
}
